/*********************************************************************************************************************
 * COPYRIGHT NOTICE
 * Copyright (c) 2018,逐飞科技
 * All rights reserved.
 * 技术讨论QQ群：	一群：179029047(已满)
 *					二群：244861897(已满)
 *					三群：824575535
 *
 * 以下所有内容版权均属逐飞科技所有，未经允许不得用于商业用途，
 * 欢迎各位使用并传播本程序，修改内容时必须保留逐飞科技的版权声明。
 *
 * @file			zf_gpio.h
 * @company			成都逐飞科技有限公司
 * @author			逐飞科技(QQ3184284598)
 * @version			查看doc内version文件 版本说明
 * @Software		IAR 8.3 or MDK 5.24
 * @Taobao			https://seekfree.taobao.com/
 * @date			2020-03-25
 * @note			本文件作为 LPC55S 系列芯片开源库外设文件
					提供 GPIO 外设驱动
 ********************************************************************************************************************/

#ifndef _ZF_GPIO_H_
#define _ZF_GPIO_H_

#include "fsl_gpio.h"

// *********************************************************** Param define *********************************************************** start

typedef enum
{
	PIO0	=	0,
	PIO1	=	1,
}group_index_list;

typedef enum
{
	PIN00	=	0,
	PIN01	=	1,
	PIN02	=	2,
	PIN03	=	3,
	PIN04	=	4,
	PIN05	=	5,
	PIN06	=	6,
	PIN07	=	7,
	PIN08	=	8,
	PIN09	=	9,
	PIN10	=	10,
	PIN11	=	11,
	PIN12	=	12,
	PIN13	=	13,
	PIN14	=	14,
	PIN15	=	15,
	PIN16	=	16,
	PIN17	=	17,
	PIN18	=	18,
	PIN19	=	19,
	PIN20	=	20,
	PIN21	=	21,
	PIN22	=	22,
	PIN23	=	23,
	PIN24	=	24,
	PIN25	=	25,
	PIN26	=	26,
	PIN27	=	27,
	PIN28	=	28,
	PIN29	=	29,
	PIN30	=	30,
	PIN31	=	31,
}pin_index_list;

//================== pin config param struct ==================
typedef union
{
	uint32_t	pin_config;									// 32 bit 寄存器对应变量
	struct
	{
		uint32_t	pin_param_func		:4;					// 管脚 func 选项寄存器 [0:4]
		uint32_t	pin_param_mode		:2;					// 管脚 mode 选项寄存器 [5:6]
		uint32_t	pin_param_slew		:1;					// 管脚 slew 选项寄存器 [7]
		uint32_t	pin_param_invert	:1;					// 管脚 invert 选项寄存器 [8]
		uint32_t	pin_param_digimode	:1;					// 管脚 digimode 选项寄存器 [9]
		uint32_t	pin_param_od		:1;					// 管脚 od 选项寄存器 [10]
		uint32_t	pin_param_asw		:1;					// 管脚 asw 选项寄存器 [11]
		uint32_t	pin_param_res		:21;				// 保留
	}param_bit;
}pin_param_t;
//================== pin config param struct ==================

//================== pin config param list ==================
typedef enum
{
	PIN_PARAM_FUNC,											// 管脚功能参数
	PIN_PARAM_MODE,											// 管脚模式参数
	PIN_PARAM_SLEW,											// 管脚速率参数
	PIN_PARAM_INVERT,										// 管脚电平反相模式参数
	PIN_PARAM_DIGIMODE,										// 管脚数字模式参数
	PIN_PARAM_OD,											// 管脚开漏选项参数
	PIN_PARAM_ASW,											// 管脚模拟模式选项参数
}pin_param_list;
//================== pin config param list ==================

//==================== IOCON PIO CONFIG ====================
//------------------ IOCON PIO FUNC [3:0] ------------------
typedef enum
{
	PIN_FUNC_0							= 0,
	PIN_FUNC_1							= 1,
	PIN_FUNC_2							= 2,
	PIN_FUNC_3							= 3,
	PIN_FUNC_4							= 4,
	PIN_FUNC_5							= 5,
	PIN_FUNC_6							= 6,
	PIN_FUNC_7							= 7,
	PIN_FUNC_8							= 8,
	PIN_FUNC_9							= 9,
}pin_func_list;
//------------------ IOCON PIO FUNC [3:0] ------------------

//------------------ IOCON PIO MODE [5:4] ------------------
typedef enum
{
	PIN_MODE_INACTIVE					= 0,
	PIN_MODE_PULL_DOWN					= 1,
	PIN_MODE_PULL_UP					= 2,
	PIN_MODE_REPEATER					= 3,
}pin_mode_list;
//------------------ IOCON PIO MODE [5:4] ------------------

//------------------- IOCON PIO SLEW [6] -------------------
typedef enum
{
	PIN_SLEW_STANDARD					= 0,
	PIN_SLEW_FAST						= 1,
}pin_slew_list;
//------------------- IOCON PIO SLEW [6] -------------------

//------------------ IOCON PIO INVERT [7] ------------------
typedef enum
{
	PIN_INVERT_DISABLED				= 0,
	PIN_INVERT_ENABLED				= 1,
}pin_invert_list;
//------------------ IOCON PIO INVERT [7] ------------------

//----------------- IOCON PIO DIGIMODE [8] -----------------
typedef enum
{
	PIN_DIGIMODE_DISABLED				= 0,
	PIN_DIGIMODE_ENABLED				= 1,
}pin_digimode_list;
//----------------- IOCON PIO DIGIMODE [8] -----------------

//-------------------- IOCON PIO OD [9] --------------------
typedef enum
{
	PIN_OD_DISABLED					= 0,
	PIN_OD_ENABLED					= 1,
}pin_od_list;
//-------------------- IOCON PIO OD [9] --------------------

//------------------- IOCON PIO ASW [10] -------------------
typedef enum
{
	PIN_ASW_DISABLED					= 0,
	PIN_ASW_ENABLED					= 1,
}pin_asw_list;
//------------------- IOCON PIO ASW [10] -------------------

//------------------- IOCON PIO DIR -------------------
typedef enum
{
	PIN_DIR_IN						= 0,
	PIN_DIR_OUT						= 1,
}pin_dir_list;
//------------------- IOCON PIO DIR -------------------

//==================== IOCON PIO CONFIG ====================

// *********************************************************** Param define *********************************************************** end

void zf_gpio_init (group_index_list pin_side, pin_index_list pin_index, pin_param_t *config, pin_dir_list dir);
void zf_gpio_default_init (group_index_list pin_side, pin_index_list pin_index, uint8_t dir);
void zf_gpio_get_default_config (pin_param_t *config);
void zf_gpio_param_set (pin_param_t *config, pin_param_list param_index, uint32_t pin_config);

void zf_gpio_output (group_index_list pin_side, pin_index_list pin_index, bool level);
void zf_gpio_output_not (group_index_list pin_side, pin_index_list pin_index);
bool zf_gpio_read (group_index_list pin_side, pin_index_list pin_index);

#endif
